<template>
  <div class="lb-dis-cash">
    <top-nav></top-nav>
    <div class="page-main">
      <div class="page-search-form">
        <el-form :inline="true" :model="searchForm" ref="searchForm">
          <el-form-item label="提现号" prop="cash_no">
            <el-input
              v-model="searchForm.cash_no"
              placeholder="请输入提现号"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <lb-button
              size="medium"
              type="primary"
              icon="el-icon-search"
              style="margin-right: 5px"
              @click="getTableDataList(1)"
              >{{ $t('action.search') }}</lb-button
            >
            <lb-button
              size="medium"
              icon="el-icon-refresh-left"
              style="margin-right: 5px"
              @click="resetForm('searchForm')"
              >{{ $t('action.reset') }}</lb-button
            >
          </el-form-item>
        </el-form>
      </div>
      <el-table
        v-loading="loading"
        :data="tableData"
        :header-cell-style="{ background: '#f5f7fa', color: '#606266' }"
        style="width: 100%"
      >
        <el-table-column prop="id" label="ID" width="60"> </el-table-column>
        <el-table-column prop="name" label="姓名"> </el-table-column>
        <el-table-column prop="nickName" label="微信昵称"> </el-table-column>
        <el-table-column prop="cash_no" label="提现号"> </el-table-column>
        <el-table-column prop="account" label="提现账号"> </el-table-column>
        <el-table-column prop="money" label="金额"> </el-table-column>
        <el-table-column prop="status" label="状态">
          <template slot-scope="scope">
            <span>{{ scope.row.status ? '已到账' : '未到账' }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="create_time" label="申请时间"> </el-table-column>
        <el-table-column label="到账时间">
          <template slot-scope="scope">
            <span>{{ scope.row.status ? scope.row.update_time : '' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <div class="table-operate">
              <lb-button
                v-if="scope.row.status === 0"
                size="mini"
                type="primary"
                @click="confirmWxCash(scope.row.id)"
                >在线转账</lb-button
              >
              <lb-button
                v-if="scope.row.status === 0"
                size="mini"
                type="danger"
                @click="confirmAccount(scope.row.id)"
                >线下转账</lb-button
              >
            </div>
          </template>
        </el-table-column>
      </el-table>
      <lb-page
        :batch="false"
        :page="searchForm.page"
        :pageSize="searchForm.limit"
        :total="total"
        @handleSizeChange="handleSizeChange"
        @handleCurrentChange="handleCurrentChange"
      >
      </lb-page>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      searchForm: {
        cash_no: '',
        limit: 10,
        page: 1
      },
      loading: false,
      total: 0,
      tableData: []
    }
  },
  activated () {
    this.getTableDataList()
  },
  methods: {
    resetForm (name) {
      this.$refs[name].resetFields()
      this.getTableDataList(1)
    },
    getTableDataList (type) {
      if (type) this.searchForm.page = 1
      this.loading = true
      let { searchForm } = this
      this.$api.getCashList(searchForm).then(res => {
        console.log(res)
        this.loading = false
        if (res.code === 200) {
          this.total = res.data.total
          this.tableData = res.data.data
        }
      })
    },
    /**
     * @method 在线转账
     */
    confirmWxCash (id) {
      this.$confirm(this.$t('tips.confirmOperate'), this.$t('tips.reminder'), {
        confirmButtonText: this.$t('action.comfirm'),
        cancelButtonText: this.$t('action.cancel'),
        type: 'warning'
      }).then(() => {
        this.$api.confirmWxCash({ id }).then(res => {
          console.log(res)
          if (res.code === 200) {
            this.$message.success(this.$t('tips.successOper'))
            this.getTableDataList()
          }
        })
      })
    },
    /**
     * @method 线下转账
     */
    confirmAccount (id) {
      this.$confirm(this.$t('tips.confirmOperate'), this.$t('tips.reminder'), {
        confirmButtonText: this.$t('action.comfirm'),
        cancelButtonText: this.$t('action.cancel'),
        type: 'warning'
      }).then(() => {
        this.$api.confirmOnCash({ id }).then(res => {
          console.log(res)
          if (res.code === 200) {
            this.$message.success(this.$t('tips.successOper'))
            this.getTableDataList()
          }
        })
      })
    },
    handleSizeChange (val) {
      this.searchForm.limit = val
      this.handleCurrentChange(1)
    },
    handleCurrentChange (val) {
      this.searchForm.page = val
      this.getTableDataList()
    }
  }
}
</script>

<style lang="scss" scoped>
.lb-dis-cash {
  width: 100%;
}
</style>
